package net.huashitong.index.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.index.entity.DepartmentEntity;
import net.huashitong.index.filter.DepartmentFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DepartmentDao extends StringDao<DepartmentEntity> {

    public List<DepartmentEntity> queryByFilterNoPage(DepartmentFilter filter){
        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getDeptType())){
            query.append(" and deptType =:deptType").setParam("deptType",
                    filter.getDeptType());
        }
        if(StringUtils.isNotBlank(filter.getDeptAddr())){
            query.append(" and deptAddr =:deptAddr").setParam("deptAddr",
                    filter.getDeptAddr());
        }
        if(StringUtils.isNotBlank(filter.getDeptCode())){
            query.append(" and deptCode =:deptCode").setParam("deptCode",
                    filter.getDeptCode());
        }
        if(StringUtils.isNotBlank(filter.getDeptName())){
            query.append(" and deptName like:deptName").setParam("deptName",
                    StringUtils.getLikewords(filter.getDeptName()));
        }
        if(StringUtils.isNotBlank(filter.getParentDeptCode())){
            query.append(" and parentDeptCode =:parentDeptCode").setParam("parentDeptCode",
                    filter.getParentDeptCode());
        }
        if(StringUtils.isNotBlank(filter.getSysId())){
            query.append(" and sysId =:sysId").setParam("sysId",
                    filter.getSysId());
        }
        query.append(" ORDER BY sort+0 asc");
        return  query.listResult();
    }
}
